package com.iqiu.cms.baiduai;

import org.json.JSONObject;

import java.util.HashMap;

/**
 * 获取token类
 */
public class AiService {

    public static String add(String image,String uname,String userId) {
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("user_info",uname );
        options.put("quality_control", "NORMAL");
        options.put("liveness_control", "LOW");

        String imageType = "BASE64";
        String groupId = "group1";
        // 人脸注册
        if(image.indexOf("base64,")>0)
            image=image.substring(image.indexOf("base64,")+7);
        JSONObject res = APIConstants.face.addUser(image, imageType, groupId, userId, options);
        System.out.println(res.toString(2));
        return res.get("error_msg").toString();
    }
    public static String update(String image,String uname,String userId) {
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("user_info",uname );
        options.put("quality_control", "NORMAL");
        options.put("liveness_control", "LOW");

        String imageType = "BASE64";
        String groupId = "group1";

        // 人脸更新
        if(image.indexOf("base64,")>0)
            image=image.substring(image.indexOf("base64,")+7);
        JSONObject res = APIConstants.face.updateUser(image, imageType, groupId,  userId, options);
        System.out.println(res.toString(2));
        return res.get("error_msg").toString();//"SUCCESS"
    }

    public static String del(Integer userId) {
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();

        String groupId = "group1";
        // 人脸删除
        JSONObject res = APIConstants.face.deleteUser(userId.toString(), groupId, options);
        return res.get("error_msg").toString();//"SUCCESS"
    }
    public static JSONObject verifyUser(String image) {
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("quality_control", "NORMAL");
        options.put("liveness_control", "LOW");
        options.put("max_user_num", "3");

        String imageType = "BASE64";
        String groupIdList = "group1";

        // 人脸搜索
        JSONObject res = APIConstants.face.search(image, imageType, groupIdList, options);
        return res;//"SUCCESS"
    }
//    public static void main(String[] args) {
//        verifyUser("D:\\aQiu\\Pictures\\Pictures\\s.jpg");
//    }
}